import request from '@/utils/request'

// 客户端场馆数据接口
export interface ClientVenueData {
  id: number
  name: string
  description?: string
  address: string
  city: string
  country: string
  capacity?: number
  status: 'ACTIVE' | 'INACTIVE' | 'MAINTENANCE'
  sortOrder: number
  createdAt: string
  updatedAt: string
  floorCount: number
  performanceCount: number
}

// 客户端场馆查询参数
export interface ClientVenueQuery {
  page?: number
  limit?: number
  city?: string
  country?: string
  status?: string
  sortBy?: 'sortOrder' | 'name' | 'createdAt' | 'city'
  sortOrder?: 'asc' | 'desc'
}

// 客户端场馆搜索参数
export interface ClientVenueSearchQuery {
  keyword?: string
  page?: number
  pageSize?: number
  city?: string
  country?: string
  sortBy?: 'sortOrder' | 'name' | 'createdAt' | 'city'
  sortOrder?: 'asc' | 'desc'
}

// 客户端场馆列表响应
export interface ClientVenueListResponse {
  venues: ClientVenueData[]
  pagination: {
    total: number
    page: number
    limit: number
    totalPages: number
  }
}

// 客户端场馆搜索响应
export interface ClientVenueSearchResponse {
  items: ClientVenueData[]
  pagination: {
    total: number
    page: number
    pageSize: number
    totalPages: number
  }
}

// 客户端场馆API
export const clientVenueApi = {
  // 获取场馆列表（支持排序）
  getList: (params?: ClientVenueQuery) =>
    request.get<ClientVenueListResponse>('/client/venues', { params }),

  // 搜索场馆（支持排序）
  search: (params?: ClientVenueSearchQuery) =>
    request.get<ApiResponse<ClientVenueSearchResponse>>('/client/venues/search', { params }),

  // 获取场馆详情
  getById: (id: number) =>
    request.get<ApiResponse<ClientVenueData>>(`/client/venues/${id}`),

  // 根据场馆获取楼层列表
  getFloorsByVenue: (venueId: number, status?: string) =>
    request.get<ApiResponse<any>>(`/client/venues/${venueId}/floors`, { 
      params: { status } 
    }),

  // 获取场馆楼层统计信息
  getVenueFloorStats: (venueId: number) =>
    request.get<ApiResponse<any>>(`/client/venues/${venueId}/floor-stats`),

  // 获取热门场馆
  getPopular: (limit?: number) =>
    request.get<ApiResponse<ClientVenueData[]>>('/client/venues/popular', { 
      params: { limit } 
    }),

  // 获取城市列表
  getCities: (country?: string) =>
    request.get<ApiResponse<Array<{ city: string; venueCount: number }>>>('/client/venues/cities', { 
      params: { country } 
    }),

  // 获取国家列表
  getCountries: () =>
    request.get<ApiResponse<Array<{ country: string; venueCount: number }>>>('/client/venues/countries')
}

// 通用API响应接口
export interface ApiResponse<T> {
  code: number
  message: string
  data: T
}
